//
//  ViewController.m
//  Music
//
//  Created by mac on 16/4/22.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "ViewController.h"
#import "ActivitySrcollView.h"

#import "AppDelegate.h"
#import "PosterModel.h"
#import "ChannelModel.h"
#import "HearModel.h"
#import "HearTableViewCell.h"
#import "HotSonglistModel.h"
#import "HotSonglistCollectionViewCell.h"
#import "SomeSongModel.h"
#import "IAmSingerModel.h"
#import "IAmSingerTableViewCell.h"
#import "NewSongModel.h"
#import "NewSongCollectionViewCell.h"
#import "UniqueRegionModel.h"
#import "UniqueRegionTableViewCell.h"
#import "AsiaNewSongModel.h"
//#import "SonglistSquareViewController.h"
//#import "RadioViewController.h"
#import "SongDetailViewController.h"
#import "SongModel.h"
//#import "EveryHearViewController.h"
#import "SonglistViewController.h"
#import "WebViewController.h"
//#import "MusicTopicViewController.h"
#import "MJRefresh.h"
#import "AlbumViewController.h"
#import "Player.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource,UICollectionViewDelegate,UICollectionViewDataSource,ActivityScrollViewDelegate,STKAudioPlayerDelegate>

@property (nonatomic , strong)  NSArray *posterArr;
@property (nonatomic , strong)  NSArray *channelArr;
@property (nonatomic , strong)  NSArray *hearArr;
@property (nonatomic , strong)  NSArray *hotSonglistArr;
@property (nonatomic , strong)  NSArray *someSongArr;
@property (nonatomic , strong)  NSArray *iAmSingerArr;
@property (nonatomic , strong)  NSArray *aNewSongArr;
@property (nonatomic , strong)  NSArray *hotMVArr;
@property (nonatomic , strong)  NSArray *uniqueRegionArr;
@property (nonatomic , strong)  NSArray *asiaNewSongArr;

@property(nonatomic, strong)NSMutableArray *tempImgArr;

@property (nonatomic , strong)  UIScrollView *bigScrollView;

@property (nonatomic , strong)  NSMutableArray *btnArr;
@property (nonatomic , strong)  UIView *channelView;

@property (nonatomic , strong)  UIView *hearView;
@property (nonatomic , strong)  UITableView *hearTableView;

@property (nonatomic , strong)  UIView *hotSonglistView;
@property (nonatomic , strong)  UICollectionView *hotSonglistCollectionView;

@property (nonatomic , strong)  UIView *someSongView;
@property (nonatomic , strong)  UICollectionView *someSongCollectionView;

@property (nonatomic , strong)  UIView *iAmSingerView;
@property (nonatomic , strong)  UITableView *iAmSingerTableView;

@property (nonatomic , strong)  UIView *aNewSongView;
@property (nonatomic , strong)  UICollectionView *aNewSongCollectionView;

@property(nonatomic, strong)ActivitySrcollView *circleView;

@property (nonatomic , strong)  UIView *uniqueRegionView;
@property (nonatomic , strong)  UITableView *uniqueRegionTableView;

@property (nonatomic , strong)  UIView *asiaNewSongView;
@property (nonatomic , strong)  UITableView *asiaNewSongTableView;
@property (nonatomic , strong) UIView *loadingView;
//@property (nonatomic , strong) TKLoadingAnimationView *tkLoadingAnimationView;
@property (nonatomic , assign)  BOOL first;
@property(nonatomic, assign)BOOL isRotation;
@property(nonatomic, strong)Player *player;
@property(nonatomic, strong)CAKeyframeAnimation *ani;
@property(nonatomic, strong) UIButton *button;
@end

@implementation ViewController

-(void)dealloc
{
    [NOTIFICATION_CENTER removeObserver:self name:@"stopPlay" object:nil];

}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"音乐";
    
   self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    [_button setBackgroundImage:[UIImage imageNamed:@"yinyue-1"] forState:UIControlStateNormal];
    _button.frame = CGRectMake(0, 0, 38, 38);
    [_button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *BBTN = [[UIBarButtonItem alloc] initWithCustomView:_button];
    self.navigationItem.rightBarButtonItem = BBTN;
    
    self.ani = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"];
    CGFloat point = M_PI_4;
    _ani.values = @[@(point),@(2 * point),@(3 * point),@(4 * point),@(5 * point),@(6 * point),@(7 * point),@(8 * point),@(9 * point)];
    _ani.repeatCount = MAXFLOAT;
    _ani.duration = 5;

    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    self.loadingView = [[UIView alloc] initWithFrame:self.view.bounds];
    self.loadingView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.loadingView];
    
//    self.tkLoadingAnimationView = [[TKLoadingAnimationView alloc] initWithFrame:CGRectMake(0, 0, 50, 50) tkLoadingAnimationViewStyle:(arc4random()%4)];
//    self.tkLoadingAnimationView.center = self.loadingView.center;
//    [self.loadingView addSubview:self.tkLoadingAnimationView];
//    [_tkLoadingAnimationView startAnimating];
    
    [self dataHandle];
    [self createBigScrollView];
    
    
    [NOTIFICATION_CENTER addObserver:self selector:@selector(stopPlay:) name:@"stopPlay" object:nil];
    self.player = [Player shareInstance];
    self.player.player.delegate = self;
    
    [NOTIFICATION_CENTER addObserver:self selector:@selector(rotate:) name:@"rotate" object:nil];
    
    
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    if (self.player.player.state == STKAudioPlayerStatePlaying) {
        [self startAni];
    }
}

-(void)rotate:(NSNotification *)notification
{
    [self startAni];
}

//- (void)viewWillAppear:(BOOL)animated{
//    [super viewWillAppear:animated];
//    if (self.player.player.state == STKAudioPlayerStatePlaying) {
//        [self startAni];
//    }
//    [Player shareInstance].player.delegate = self;
//}

- (void)startAni{
  [self.navigationItem.rightBarButtonItem.customView.layer addAnimation:_ani forKey:@"lalala"];
}

- (void)removeAni{
    [self.navigationItem.rightBarButtonItem.customView.layer removeAnimationForKey:@"lalala"];
}

- (void)stopPlay:(NSNotification *)notification{
    [self startAni];
    
}

-(void)buttonAction:(UIButton *)btn
{


//    if (self.player.songArr.count) {
//        
//        if (STKAudioPlayerStatePlaying == self.player.player.state) {
//            //[self.player pause];
//            [self startAni];
//            //btn.selected = NO;
//        }
//     else if (STKAudioPlayerStatePaused == self.player.player.state) {
//            // 继续
//            //[self.player resume];
//            [self removeAni];
//            //btn.selected = YES;
//        }
//    }
//        
//        
    
        SongDetailViewController *sdVC = [SongDetailViewController new];
        [self presentViewController:sdVC animated:YES completion:nil];
    

    

    
  }

-(void)dataHandle
{
    NSString *str = @"http://api.dongting.com/frontpage/frontpage";
    [NetworkHandle GetDataWithURL:str dic:nil success:^(id responseObject) {
        
        self.first = NO;
        
        NSArray *arr = responseObject[@"data"];
        
        // 海报部分
        NSArray *posterArr = arr[0][@"data"];
        self.posterArr = [PosterModel transformWithArray:posterArr];
        
        // 轮播图
        NSMutableArray *tempImgArr = [NSMutableArray array];
        for (PosterModel *posterModel in self.posterArr) {
            NSString *str = posterModel.picUrl;
            [tempImgArr addObject:str];
        }
        [self.circleView setImages:tempImgArr];
        
        // 大家都在听部分
        NSArray *hearArr = arr[2][@"data"][0][@"songs"];
        self.hearArr = [HearModel transformWithArray:hearArr];
        [_hearTableView reloadData];
        
        // 热门歌单
        NSArray *hotSonglistArr = arr[3][@"data"];
        self.hotSonglistArr = [HotSonglistModel transformWithArray:hotSonglistArr];
        [_hotSonglistCollectionView reloadData];
        
        // 总有一些歌，让你相信爱情
        NSArray *someSongArr = arr[4][@"data"];
        self.someSongArr = [HotSonglistModel transformWithArray:someSongArr];
        [_someSongCollectionView reloadData];
        
        // 新歌新碟
        NSArray *aNewSongArr = arr[6][@"data"];
        self.aNewSongArr = [NewSongModel transformWithArray:aNewSongArr];
        [_aNewSongCollectionView reloadData];
        
        // 独家专区
        NSArray *uniqueRegionArr = arr[8][@"data"];
        self.uniqueRegionArr = [UniqueRegionModel transformWithArray:uniqueRegionArr];
        [_uniqueRegionTableView reloadData];
        
        // 亚洲新歌榜
        NSArray *asiaNewSongArr = arr[9][@"data"];
        self.asiaNewSongArr = [AsiaNewSongModel transformWithArray:asiaNewSongArr];
        [_asiaNewSongTableView reloadData];
        
        //[self.tkLoadingAnimationView stopAnimating];
        [self.loadingView removeFromSuperview];
        
        //[self.bigScrollView.header endRefreshing];
    } filed:^(NSError *error) {
         self.first = NO;
       // [self.bigScrollView.header endRefreshing];
    }];

}

- (void)createBigScrollView{
    self.bigScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height - 64)];
    _bigScrollView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_bigScrollView];
    
    [self createCircleView];
    [self createHearView];
    [self createHotSonglistView];
    [self createSomeSongView];
    //[self createIAmSingerView];
    [self createaNewSongView];
    [self createUniqueRegionView];
    [self createAsiaNewSongView];
    _bigScrollView.contentSize = CGSizeMake(_bigScrollView.frame.size.width, _asiaNewSongView.frame.origin.y + _asiaNewSongView.frame.size.height);
//    [self.bigScrollView addLegendHeaderWithRefreshingBlock:^{
//        [self dataHandle];
//    }];
}

- (void)createCircleView{
    self.circleView = [[ActivitySrcollView alloc] initWithFrame:CGRectMake(0, 0, self.bigScrollView.frame.size.width, 200)];
    [_bigScrollView addSubview:_circleView];

}

- (void)createHearView{
    self.hearView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_circleView.frame) +5, self.view.frame.size.width, 280)];
    [_bigScrollView addSubview:_hearView];
    _hearView.backgroundColor = [UIColor whiteColor];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 5, 100, 30)];
    titleLabel.text = @"大家都在听";
    //titleLabel.font = [UIFont systemFontOfSize:20];
    [_hearView addSubview:titleLabel];
    titleLabel.backgroundColor = [UIColor whiteColor];
    UILabel *detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(titleLabel.frame.origin.x + titleLabel.frame.size.width + 5, 0, 100, 20)];
    detailLabel.text = @"每小时更新";
    detailLabel.center = CGPointMake(detailLabel.center.x, titleLabel.center.y);
    detailLabel.textColor = [UIColor grayColor];
    [_hearView addSubview:detailLabel];
    detailLabel.backgroundColor = [UIColor whiteColor];
    
    self.hearTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 40, self.view.frame.size.width, 280 - 40) style:(UITableViewStylePlain)];
    _hearTableView.dataSource = self;
    _hearTableView.delegate = self;
    _hearTableView.rowHeight = 80;
    _hearTableView.bounces = NO;
    _hearTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [_hearView addSubview:_hearTableView];
    [_hearTableView registerClass:[HearTableViewCell class] forCellReuseIdentifier:@"hearCell"];
    
    UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _hearView.frame.size.width, 0.5)];
    topView.backgroundColor = [UIColor lightGrayColor];
    [_hearView addSubview:topView];
    
    UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, _hearView.frame.size.height - 0.5, _hearView.frame.size.width, 0.5)];
    bottomView.backgroundColor = [UIColor lightGrayColor];
    [_hearView addSubview:bottomView];
}

- (void)createHotSonglistView{
    self.hotSonglistView = [[UIView alloc] initWithFrame:CGRectMake(0, _hearView.frame.origin.y + _hearView.frame.size.height, _bigScrollView.frame.size.width, 405)];
    [_bigScrollView addSubview:_hotSonglistView];
    _hotSonglistView.backgroundColor = [UIColor whiteColor];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, kWIDTH, 30)];
    titleLabel.text = @"热门歌单";
    //titleLabel.font = [UIFont systemFontOfSize:20];
    titleLabel.textAlignment = 1;
    [_hotSonglistView addSubview:titleLabel];
    titleLabel.backgroundColor = [UIColor whiteColor];
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.minimumInteritemSpacing = 20;
    layout.minimumLineSpacing = 20;
    layout.sectionInset = UIEdgeInsetsMake(5, 20, 20, 20);
    CGFloat w = (_hotSonglistView.frame.size.width - 20 * 2 - 2 * 20) / 3.0;
    layout.itemSize = CGSizeMake(w, 160);
    
    self.hotSonglistCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 40, _hotSonglistView.frame.size.width, _hotSonglistView.frame.size.height - 40) collectionViewLayout:layout];
    _hotSonglistCollectionView.delegate = self;
    _hotSonglistCollectionView.dataSource = self;
    [_hotSonglistView addSubview:_hotSonglistCollectionView];
    _hotSonglistCollectionView.backgroundColor = [UIColor whiteColor];
    [_hotSonglistCollectionView registerClass:[HotSonglistCollectionViewCell class] forCellWithReuseIdentifier:@"hotSonglistCell"];
    
    UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, _hotSonglistView.frame.size.height - 0.5, _hotSonglistView.frame.size.width, 0.5)];
    bottomView.backgroundColor = [UIColor lightGrayColor];
    [_hotSonglistView addSubview:bottomView];
}

- (void)createSomeSongView{
    self.someSongView = [[UIView alloc] initWithFrame:CGRectMake(0, _hotSonglistView.frame.origin.y + _hotSonglistView.frame.size.height, _bigScrollView.frame.size.width, 225)];
    [_bigScrollView addSubview:_someSongView];
    _someSongView.backgroundColor = [UIColor whiteColor];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, kWIDTH, 30)];
    titleLabel.text = @"你是人间的四月天";
    titleLabel.textAlignment = 1;
    [_someSongView addSubview:titleLabel];
    titleLabel.backgroundColor = [UIColor whiteColor];
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.minimumInteritemSpacing = 20;
    layout.minimumLineSpacing = 20;
    layout.sectionInset = UIEdgeInsetsMake(5, 20, 20, 20);
    CGFloat w = (_hotSonglistView.frame.size.width - 20 * 2 - 2 * 20) / 3.0;
    layout.itemSize = CGSizeMake(w, 160);
    
    self.someSongCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 40, _someSongView.frame.size.width, _someSongView.frame.size.height - 40) collectionViewLayout:layout];
    _someSongCollectionView.delegate = self;
    _someSongCollectionView.dataSource = self;
    [_someSongView addSubview:_someSongCollectionView];
    _someSongCollectionView.backgroundColor = [UIColor whiteColor];
    [_someSongCollectionView registerClass:[HotSonglistCollectionViewCell class] forCellWithReuseIdentifier:@"someSongCell"];
    
    UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, _someSongView.frame.size.height - 0.5, _someSongView.frame.size.width, 0.5)];
    bottomView.backgroundColor = [UIColor lightGrayColor];
    [_someSongView addSubview:bottomView];
}

- (void)createaNewSongView{
    self.aNewSongView = [[UIView alloc] initWithFrame:CGRectMake(0,CGRectGetMaxY(_someSongView.frame), _bigScrollView.frame.size.width, 225)];
    [_bigScrollView addSubview:_aNewSongView];
    _aNewSongView.backgroundColor = [UIColor whiteColor];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, kWIDTH, 30)];
    titleLabel.text = @"新歌新碟";
    titleLabel.textAlignment = 1;
    [_aNewSongView addSubview:titleLabel];
    titleLabel.backgroundColor = [UIColor whiteColor];
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.minimumInteritemSpacing = 20;
    layout.minimumLineSpacing = 20;
    layout.sectionInset = UIEdgeInsetsMake(5, 20, 20, 20);
    CGFloat w = (_aNewSongView.frame.size.width - 20 * 2 - 2 * 20) / 3.0;
    layout.itemSize = CGSizeMake(w, 160);
    
    self.aNewSongCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 40, _aNewSongView.frame.size.width, _aNewSongView.frame.size.height - 40) collectionViewLayout:layout];
    _aNewSongCollectionView.delegate = self;
    _aNewSongCollectionView.dataSource = self;
    [_aNewSongView addSubview:_aNewSongCollectionView];
    _aNewSongCollectionView.backgroundColor = [UIColor whiteColor];
    [_aNewSongCollectionView registerClass:[NewSongCollectionViewCell class] forCellWithReuseIdentifier:@"newSongCell"];
    
    UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, _aNewSongView.frame.size.height - 0.5, _aNewSongView.frame.size.width, 0.5)];
    bottomView.backgroundColor = [UIColor lightGrayColor];
    [_aNewSongView addSubview:bottomView];
}

- (void)createUniqueRegionView{
    self.uniqueRegionView = [[UIView alloc]initWithFrame:CGRectMake(0, _aNewSongView.frame.origin.y + _aNewSongView.frame.size.height, self.view.frame.size.width, 540)];
    [_bigScrollView addSubview:_uniqueRegionView];
    _uniqueRegionView.backgroundColor = [UIColor whiteColor];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, kWIDTH, 30)];
    titleLabel.text = @"独家专区";
    titleLabel.textAlignment = 1;
    [_uniqueRegionView addSubview:titleLabel];
    titleLabel.backgroundColor = [UIColor whiteColor];
    
    self.uniqueRegionTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 40, self.view.frame.size.width, _uniqueRegionView.frame.size.height - 40) style:(UITableViewStylePlain)];
    _uniqueRegionTableView.dataSource = self;
    _uniqueRegionTableView.delegate = self;
    _uniqueRegionTableView.rowHeight = 100;
    _uniqueRegionTableView.bounces = NO;
    _uniqueRegionTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [_uniqueRegionView addSubview:_uniqueRegionTableView];
    
    UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, _uniqueRegionView.frame.size.height - 0.5, _uniqueRegionView.frame.size.width, 0.5)];
    bottomView.backgroundColor = [UIColor lightGrayColor];
    [_uniqueRegionView addSubview:bottomView];
}

- (void)createAsiaNewSongView{
    self.asiaNewSongView = [[UIView alloc]initWithFrame:CGRectMake(0, _uniqueRegionView.frame.origin.y + _uniqueRegionView.frame.size.height, self.view.frame.size.width, 140)];
    [_bigScrollView addSubview:_asiaNewSongView];
    _asiaNewSongView.backgroundColor = [UIColor whiteColor];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, kWIDTH, 30)];
    titleLabel.text = @"亚洲新歌榜";
    titleLabel.textAlignment = 1;
    [_asiaNewSongView addSubview:titleLabel];
    titleLabel.backgroundColor = [UIColor whiteColor];
    
    self.asiaNewSongTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 40, self.view.frame.size.width, _asiaNewSongView.frame.size.height - 40) style:(UITableViewStylePlain)];
    _asiaNewSongTableView.dataSource = self;
    _asiaNewSongTableView.delegate = self;
    _asiaNewSongTableView.rowHeight = 100;
    _asiaNewSongTableView.bounces = NO;
    _asiaNewSongTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [_asiaNewSongView addSubview:_asiaNewSongTableView];
    
    UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, _asiaNewSongView.frame.size.height - 0.5, _asiaNewSongView.frame.size.width, 0.5)];
    bottomView.backgroundColor = [UIColor lightGrayColor];
    [_asiaNewSongView addSubview:bottomView];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView == _hearTableView) {
        return _hearArr.count;
    }
    if (tableView == _uniqueRegionTableView) {
        return _uniqueRegionArr.count;
    }
    if (tableView == _asiaNewSongTableView) {
        return _asiaNewSongArr.count;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == _hearTableView) {
        HearTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"hearCell" forIndexPath:indexPath];
        HearModel *hearModel = _hearArr[indexPath.row];
        
        cell.numLabel.text = [NSString stringWithFormat:@"%ld",(indexPath.row + 1)];
        
        [cell.imgView sd_setImageWithURL:[NSURL URLWithString:hearModel.picUrl]];
        cell.songNameLabel.text = hearModel.name;
        cell.singerLabel.text = hearModel.singerName;
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
        NSInteger count = [hearModel.favorites integerValue];
        NSString *str = nil;
        if (count >= 10000) {
            CGFloat num = count / 10000.0;
            if (count % 10000 >= 1000) {
                str = [NSString stringWithFormat:@"%.1f 万",num];
            } else {
                str = [NSString stringWithFormat:@"%.0f 万",num];
            }
        } else {
            str = [NSString stringWithFormat:@"%ld",count];
        }
        cell.countLabel.text = str;
        return cell;
    }
    if (tableView == _uniqueRegionTableView) {
        UniqueRegionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"uniqueRegionCell"];
        if (!cell) {
            cell = [[UniqueRegionTableViewCell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:@"uniqueRegionCell"];
        }
        UniqueRegionModel *urModel = _uniqueRegionArr[indexPath.row];
        NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urModel.picUrl]];
        cell.imageView.image = [UIImage imageWithData:data];
        cell.imageView.frame = CGRectMake(cell.imageView.frame.origin.x, cell.imageView.frame.origin.y + 5, cell.imageView.frame.size.width, cell.imageView.frame.size.height - 10);
        cell.textLabel.text = urModel.name;
        cell.detailTextLabel.text = urModel.desc;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        return cell;
    }
    if (tableView == _asiaNewSongTableView) {
        UniqueRegionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"asiaNewSongCell"];
        if (!cell) {
            cell = [[UniqueRegionTableViewCell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:@"asiaNewSongCell"];
        }
        AsiaNewSongModel *ansModel = _asiaNewSongArr[indexPath.row];
        NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:ansModel.picUrl]];
        cell.imageView.image = [UIImage imageWithData:data];
        cell.imageView.frame = CGRectMake(cell.imageView.frame.origin.x, cell.imageView.frame.origin.y + 5, cell.imageView.frame.size.width, cell.imageView.frame.size.height - 10);
        cell.textLabel.text = ansModel.name;
        cell.detailTextLabel.text = ansModel.desc;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        return cell;
    }
    
    return nil;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if (collectionView == _hotSonglistCollectionView) {
        return _hotSonglistArr.count;
    }
    if (collectionView == _someSongCollectionView) {
        return _someSongArr.count;
    }
    if (collectionView == _aNewSongCollectionView) {
        return _aNewSongArr.count;
    }
    return 0;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (collectionView == _hotSonglistCollectionView) {
        HotSonglistCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"hotSonglistCell" forIndexPath:indexPath];
        HotSonglistModel *hsModel = _hotSonglistArr[indexPath.item];
        [cell.coverPic sd_setImageWithURL:[NSURL URLWithString:hsModel.picUrl]];
        cell.name.text = hsModel.name;
        [cell.name sizeToFit];
        cell.author.text = hsModel.author;
        NSInteger listenCount = [hsModel.listenCount integerValue];
        NSString *countStr = nil;
        if (listenCount > 10000) {
            CGFloat r = listenCount / 10000.0;
            if (listenCount % 10000  > 1000) {
                countStr = [NSString stringWithFormat:@"%.1f万",r];
            } else{
                countStr = [NSString stringWithFormat:@"%.0f万",r];
            }
        } else {
            countStr = [NSString stringWithFormat:@"%ld",listenCount];
        }
        cell.listenCount.text = countStr;
        [cell.listenCount sizeToFit];
        cell.listenCount.frame = CGRectMake(cell.coverPic.frame.size.width - 5 - cell.listenCount.frame.size.width, cell.listenCount.frame.origin.y, cell.listenCount.frame.size.width, cell.listenCount.frame.size.height);
        cell.detailImg.frame = CGRectMake(cell.listenCount.frame.origin.x - cell.detailImg.frame.size.width, cell.detailImg.frame.origin.y, cell.detailImg.frame.size.width, cell.detailImg.frame.size.height);
        return cell;
    }
    if (collectionView == _someSongCollectionView) {
        HotSonglistCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"someSongCell" forIndexPath:indexPath];
        HotSonglistModel *hsModel = _someSongArr[indexPath.item];
        [cell.coverPic sd_setImageWithURL:[NSURL URLWithString:hsModel.picUrl]];
        cell.name.text = hsModel.name;
        [cell.name sizeToFit];
        cell.author.text = hsModel.author;
        NSInteger listenCount = [hsModel.listenCount integerValue];
        NSString *countStr = nil;
        if (listenCount > 10000) {
            CGFloat r = listenCount / 10000.0;
            if (listenCount % 10000  > 1000) {
                countStr = [NSString stringWithFormat:@"%.1f万",r];
            } else{
                countStr = [NSString stringWithFormat:@"%.0f万",r];
            }
        } else {
            countStr = [NSString stringWithFormat:@"%ld",listenCount];
        }
        cell.listenCount.text = countStr;
        [cell.listenCount sizeToFit];
        cell.listenCount.frame = CGRectMake(cell.coverPic.frame.size.width - 5 - cell.listenCount.frame.size.width, cell.listenCount.frame.origin.y, cell.listenCount.frame.size.width, cell.listenCount.frame.size.height);
        cell.detailImg.frame = CGRectMake(cell.listenCount.frame.origin.x - cell.detailImg.frame.size.width, cell.detailImg.frame.origin.y, cell.detailImg.frame.size.width, cell.detailImg.frame.size.height);
        return cell;
    }
    if (collectionView == _aNewSongCollectionView) {
        NewSongCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"newSongCell" forIndexPath:indexPath];
        NewSongModel *nsModel = _aNewSongArr[indexPath.item];
        [cell.coverPic sd_setImageWithURL:[NSURL URLWithString:nsModel.picUrl]];
        cell.name.text = nsModel.name;
        [cell.name sizeToFit];
        return cell;
    }
    return nil;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (tableView == self.hearTableView) {
        NSString *str = @"http://api.favorite.ttpod.com/favorite/song/plaza?random=0";
        [NetworkHandle GetDataWithURL:str dic:nil success:^(id responseObject) {
            NSArray *tempArr = responseObject[@"data"][@"songs"];
            NSArray *songArr = [SongModel transformWithArray:tempArr];
            [NOTIFICATION_CENTER postNotificationName:@"playSongs" object:songArr userInfo:@{@"type":@"Song",@"indexPath":indexPath}];
        } filed:^(NSError *error) {
            
        }];
        
    }
    if (tableView == self.asiaNewSongTableView){
        WebViewController *webVC = [[WebViewController alloc] init];
        AsiaNewSongModel *asiaNewSongModel = self.asiaNewSongArr[indexPath.row];
        webVC.urlStr = asiaNewSongModel.aValue;
        [self.navigationController pushViewController:webVC animated:YES];

    }
    if (tableView == self.uniqueRegionTableView) {
        UniqueRegionModel *uniqueRegionModel = self.uniqueRegionArr[indexPath.row];
        if ([uniqueRegionModel.uType isEqualToNumber:@(19)]) {
            AlbumViewController *albumVC = [[AlbumViewController alloc] init];
            albumVC.albumId = uniqueRegionModel.uValue;
            [self.navigationController pushViewController:albumVC animated:YES];

        }
        if ([uniqueRegionModel.uType isEqualToNumber:@(1)]) {
            WebViewController *webVC = [[WebViewController alloc] init];
            webVC.urlStr = uniqueRegionModel.uValue;
            [self.navigationController pushViewController:webVC animated:YES];
        }
        
    }
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (collectionView == _hotSonglistCollectionView) {
        SonglistViewController *songlistVC = [[SonglistViewController alloc] init];
        HotSonglistModel *hotSonglistModel = self.hotSonglistArr[indexPath.item];
        songlistVC.songlist_id = hotSonglistModel.hValue;
        [self.navigationController pushViewController:songlistVC animated:YES];
    }
    if (collectionView == _someSongCollectionView) {
        SonglistViewController *songlistVC = [[SonglistViewController alloc] init];
        HotSonglistModel *someSongModel = self.someSongArr[indexPath.item];
        songlistVC.songlist_id = someSongModel.hValue;
        [self.navigationController pushViewController:songlistVC animated:YES];
    }
    if (collectionView == _aNewSongCollectionView) {
        AlbumViewController *albumVC = [[AlbumViewController alloc] init];
        NewSongModel *model = self.aNewSongArr[indexPath.item];
        albumVC.albumId = model.nValue;
        [self.navigationController pushViewController:albumVC animated:YES];

    }
}




#pragma mark - player代理方法
- (void)audioPlayer:(STKAudioPlayer *)audioPlayer didFinishPlayingQueueItemId:(NSObject *)queueItemId withReason:(STKAudioPlayerStopReason)stopReason andProgress:(double)progress andDuration:(double)duration{
//    if ((self.i <= (self.dataArr.count - 1)) && ((stopReason == 1) || duration < progress)) {
//        if (self.circleType == 0) {
//            if (self.i == self.dataArr.count - 1) {
//                self.i = 0;
//            } else{
//                self.i++;
//            }
//        } else if (self.circleType == 1){
//            
//        } else {
//            self.i = arc4random() % (self.dataArr.count);
//        }
//        
//        [_currCell removeAni];
//        NSIndexPath *index = [NSIndexPath indexPathForItem:_i inSection:0];
//        [self.collectionView scrollToItemAtIndexPath:index atScrollPosition:(UICollectionViewScrollPositionRight) animated:YES];
//        self.currCell = (MyCollectionViewCell *)[_collectionView cellForItemAtIndexPath:index];
//        [_currCell startAni];
//        
//        [self.player stop];
//        self.player.num = self.i;
//        [self.player play];
//    }
}

- (void)audioPlayer:(STKAudioPlayer *)audioPlayer didStartPlayingQueueItemId:(NSObject *)queueItemId{
    
}

- (void)audioPlayer:(STKAudioPlayer *)audioPlayer didFinishBufferingSourceWithQueueItemId:(NSObject *)queueItemId{
    
}
- (void)audioPlayer:(STKAudioPlayer *)audioPlayer stateChanged:(STKAudioPlayerState)state previousState:(STKAudioPlayerState)previousState{
    
}

- (void)audioPlayer:(STKAudioPlayer *)audioPlayer unexpectedError:(STKAudioPlayerErrorCode)errorCode{
    
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
